//---------------------------------------------------------------------------------
#ifndef __CMAP_H__
#define __CMAP_H__
//---------------------------------------------------------------------------------
#include <QMap>
#include "CCase.h"
//---------------------------------------------------------------------------------
#define NB_ACTION			8
//---------------------------------------------------------------------------------
class CMap {
	public:
		typedef enum { eaMoveUp=0, eaMoveDown=1, eaMoveRight=2, eaMoveLeft=3, eaPushUp=4, eaPushDown=5, eaPushRight=6, eaPushLeft=7 } EAction;
		
		CMap(void) { width=0; height=0; selectedCase=0; }
		~CMap(void);
		void draw(QPainter* painter, int x, int y, int step);
		void load(QString fileName);
		CCase* getCase(int x, int y);
		CCase* getCase(int index);
		int getNbCase(void) { return cases.size(); }
		bool addCase(CCase* c);
		bool canMoveUp(int x, int y);
		bool canMoveDown(int x, int y);
		bool canMoveRight(int x, int y);
		bool canMoveLeft(int x, int y);
		bool canPushUp(int x, int y);
		bool canPushDown(int x, int y);
		bool canPushRight(int x, int y);
		bool canPushLeft(int x, int y);
		void setPlayerPos(int x, int y) { xPlayer=x; yPlayer=y; }
		void getPlayerPos(int& x, int& y) { x=xPlayer; y=yPlayer; }
		void clean(void);
		void getSize(int& width, int& height) { width=this->width; height=this->height; }
		bool hasWin(void);
		void moveUp(void) { yPlayer--; }
		void moveDown(void) { yPlayer++; }
		void moveRight(void) { xPlayer++; }
		void moveLeft(void) { xPlayer--; }
		void pushUp(void);
		void pushDown(void);
		void pushRight(void);
		void pushLeft(void);
		void setSelectedCase(int x, int y);
		CCase* getSelectedCase(void) { return selectedCase; }
		void noSelectedCase(void) { selectedCase=0; }
		CMap* clone(void);
	private:
		QMap<QString, CCase*> cases;
		int xPlayer;
		int yPlayer;
		int width;
		int height;
		CCase* selectedCase;
		
		bool canMove(CCase *o, CCase *d);
		bool canPush(CCase *o, CCase *d, CCase *ds);
};
//---------------------------------------------------------------------------------
#endif //__CMAP_H__
//---------------------------------------------------------------------------------